package com.sskj.cndragon.presenter;

import com.lzy.okgo.model.Response;
import com.shizhefei.view.coolrefreshview.CoolRefreshView;
import com.sskj.cndragon.bean.LastTimeBean;
import com.sskj.cndragon.bean.OrderBuyListBean;
import com.sskj.cndragon.http.HttpConfig;
import com.sskj.cndragon.ui.activity.OrderBuyDetailActivity;
import com.sskj.common.base.HttpData;
import com.sskj.common.util.ToastUtil;
import com.sskj.lib.http.JsonCallBack;

import java.io.File;
import java.lang.annotation.Repeatable;


public class OrderBuyDetailActivityPresenter extends BasePresenter<OrderBuyDetailActivity> {

    public void getOrderDetail(String orderID, CoolRefreshView coolRefreshView) {
        httpService.getOrderDetail(orderID)
                .tag(this)
                .execute(new JsonCallBack<HttpData<OrderBuyListBean.OrderBuyBean>>(this) {
                    @Override
                    public void onSuccess(Response<HttpData<OrderBuyListBean.OrderBuyBean>> response) {
                        if (coolRefreshView != null && coolRefreshView.isRefreshing()) {
                            coolRefreshView.setRefreshing(false);
                        }
                        HttpData<OrderBuyListBean.OrderBuyBean> body = response.body();
                        if (body.getStatus() == HttpConfig.OK) {
                            mView.updataOrderDetail(body.getData());
                        } else {
                            ToastUtil.showShort(body.getMsg());
                        }

                    }
                });
    }

    public void uploadFile(File file) {
        httpService.uploadFile(file)
                .tag(this)
                .execute(new JsonCallBack<HttpData<String>>(this) {
                    @Override
                    public void onSuccess(Response<HttpData<String>> response) {
                        HttpData body = response.body();
                        if (body.getStatus() == HttpConfig.OK) {
                            mView.uploadImg((String) body.getData());
                        } else {
                            ToastUtil.showShort(body.getMsg());
                        }
                    }
                });
    }

    public void uploadPayImg(String orderID, String img) {
        httpService.uploadPayImg(orderID, img)
                .tag(this)
                .execute(new JsonCallBack<HttpData>() {
                    @Override
                    public void onSuccess(Response<HttpData> response) {
                        HttpData body = response.body();
                        ToastUtil.showShort(body.getMsg());
                        if (body.getStatus() == HttpConfig.OK) {
                            mView.uploadImgOK(img);
                        }

                    }
                });

    }

    public void markPay(String orderID) {
        httpService.markPay(orderID)
                .tag(this)
                .execute(new JsonCallBack<HttpData>(this) {
                    @Override
                    public void onSuccess(Response<HttpData> response) {
                        HttpData body = response.body();
                        ToastUtil.showShort(body.getMsg());
                        if (body.getStatus() == HttpConfig.OK) {
                            mView.markPayOK();
                        }

                    }
                });
    }

    public void getLastTime(int countDownType) {
        httpService.getLastTime()
                .tag(this)
                .execute(new JsonCallBack<HttpData<LastTimeBean>>() {
                    @Override
                    public void onSuccess(Response<HttpData<LastTimeBean>> response) {
                        HttpData<LastTimeBean> body = response.body();
                        if (body.getStatus() == HttpConfig.OK) {
                            mView.getLastTimeOK(body.getData(),countDownType);
                        }
                    }
                });
    }

    public void timeOut(String orderID) {
        httpService.timeOut(orderID)
                .tag(this)
                .execute(new JsonCallBack<HttpData>() {
                    @Override
                    public void onSuccess(Response<HttpData> response) {

                    }
                });
    }
}
